package com.swind.fast.modules.app.halali.partner.service.impl;

import com.swind.fast.common.util.oConvertUtils;

import com.swind.fast.modules.app.halali.partner.entity.BankAccount;
import com.swind.fast.modules.app.halali.partner.mapper.BankAccountMapper;
import com.swind.fast.modules.app.halali.partner.service.IBankAccountService;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.ApplicationContext;

import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.hutool.core.date.DateBetween;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;

import javax.annotation.Resource;

import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import org.springframework.beans.BeanUtils;
import com.swind.fast.modules.app.halali.partner.vo.request.BankAccountVo;

/**
 * @Description: 项目
 * @Author: swind
 * @Date:   2021-11-20
 * @Version: V1.0
 */
@Slf4j
@Service
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements IBankAccountService {

    public BankAccount getByRestaurantId(String id) {
        BankAccount item = this.baseMapper.queryBankAccountByRestaurantId(id);
        return item;
    }

    public BankAccount saveMain(BankAccountVo bankInfo) {
        String restaurantId = bankInfo.getRestaurantId();
        BankAccount item = this.getByRestaurantId(restaurantId);
        if (oConvertUtils.isNotEmpty(item)) {
            BeanUtils.copyProperties(bankInfo, item);
            this.updateById(item);
            item = this.getByRestaurantId(restaurantId);
        } else {
            item = oConvertUtils.entityToModel(bankInfo, BankAccount.class);
            this.save(item);
        }
        return item;
    }
}
